// ==========================================================================
// gin-sns自动生成业务逻辑层相关代码，只生成一次，按需修改,再次生成不会覆盖.
// 生成日期：2020-02-17 14:03:51
// 生成路径: app/service/module/online/online_service.go
// 生成人：jon
// ==========================================================================
package monitor

import (
	"errors"
	"gin-sns/app/dao/monitor/online"
	"gin-sns/app/ginframe/utils/page"
	onlineModel "gin-sns/app/model/monitor/online"
	"strings"
)

var OnlineService = newOnlineService()

func newOnlineService() *onlineService {
	return &onlineService{}
}

type onlineService struct {
}

//根据主键查询数据
func (s *onlineService) SelectRecordById(id string) (*onlineModel.Entity, error) {
	entity := &onlineModel.Entity{Sessionid: id}
	have, err := online.UserOnlineDao.FindOne(entity)
	if !have {
		err = errors.New("not found")
	}
	return entity, err
}

//根据主键删除数据
func (s *onlineService) DeleteRecordById(id string) bool {
	entity := &onlineModel.Entity{Sessionid: id}
	result, err := online.UserOnlineDao.Delete(entity)
	if err == nil && result > 0 {
		return true
	}

	return false
}

//批量删除数据记录
func (s *onlineService) DeleteRecordByIds(ids string) int64 {
	idarr := strings.Split(ids, ",")
	result, _ := online.UserOnlineDao.DeleteBatch(idarr...)
	return result
}

//批量删除数据
func (s *onlineService) DeleteRecordNotInIds(ids []string) int64 {
	result, _ := online.UserOnlineDao.DeleteNotIn(ids...)
	return result
}

//添加数据
func (s *onlineService) AddSave(entity onlineModel.Entity) (int64, error) {
	return online.UserOnlineDao.Insert(&entity)
}

//根据条件查询数据
func (s *onlineService) SelectListAll(params *onlineModel.SelectPageReq) ([]onlineModel.Entity, error) {
	return online.UserOnlineDao.SelectListAll(params)
}

//根据条件分页查询数据
func (s *onlineService) SelectListByPage(params *onlineModel.SelectPageReq) ([]onlineModel.Entity, *page.Paging, error) {
	return online.UserOnlineDao.SelectListByPage(params)
}
